﻿#region copyright
// Halcyone - Silverlight Application Framework
// Copyright (C) 2009 - 2010 Alexey Zakharov (B&Z LLC)
// 
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#endregion
using System.Web;
using Microsoft.Practices.ServiceLocation;

namespace Witcraft.Halcyone.ASPFacility
{
    /// <summary>
    /// dependency injection http handler factory.
    /// </summary>
    public class DependencyInjectionHttpHandlerFactory : IHttpHandlerFactory
    {
        #region IHttpHandlerFactory Members

        /// <summary>
        /// Returns an instance of a class that implements the <see cref="T:System.Web.IHttpHandler"/> interface.
        /// </summary>
        /// <returns>
        /// A new <see cref="T:System.Web.IHttpHandler"/> object that processes the request.
        /// </returns>
        /// <param name="context">
        /// An instance of the <see cref="T:System.Web.HttpContext"/> class that provides references to intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests. 
        /// </param>
        /// <param name="requestType">
        /// The HTTP data transfer method (GET or POST) that the client uses. 
        /// </param>
        /// <param name="url">
        /// The <see cref="P:System.Web.HttpRequest.RawUrl"/> of the requested resource. 
        /// </param>
        /// <param name="pathTranslated">
        /// The <see cref="P:System.Web.HttpRequest.PhysicalApplicationPath"/> to the requested resource. 
        /// </param>
        public IHttpHandler GetHandler(HttpContext context, string requestType, string url, string pathTranslated)
        {
            return ServiceLocator.GetCurrent("MVC").GetInstance<IHttpHandler>(url);
        }

        /// <summary>
        /// Enables a factory to reuse an existing handler instance.
        /// </summary>
        /// <param name="handler">
        /// The <see cref="T:System.Web.IHttpHandler"/> object to reuse. 
        /// </param>
        public void ReleaseHandler(IHttpHandler handler)
        {
        }

        #endregion
    }
}